﻿using Core.DataAccess.Model.Project.Comment;
using Core.DataAccess.Model.Project.Information;
using Core.Framework.Model.Common;
using Core.Framework.Util;
using Core.IBusiness.IComment;
using Core.IBusiness.IInformation.Model;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;

namespace Core.Web.Controllers.Information
{
    /// <summary>
    /// 信息评论回复管理
    /// </summary>
    [Route(".v1/CommentReply/[controller]")]
    [ApiController]
    public class CommentReplyController : BaseApiController
    {

        public CommentReplyController(ICommentModule iComment) :
            base(iComment: iComment)
        {

        }

        #region Serach

        /// <summary>
        /// 查询指定评论回复
        /// </summary>
        /// <param name="model">查询暂时</param>
        /// <returns></returns>
        [HttpPost("getcommentReply")]
        [IgnoreAuthorize]
        public IResult GetCommentReply(CommentReplyRequest model)
        {
            return this.ExecMethod(
                () => {
                    return this.Result(this.iComment.GetCommentReply(
                        model.commentKey,
                        model.pagination,
                        model.attributes),model.pagination);
                },
                model.IsValid(IsValidEnum.select));
        }


        #endregion







        #region Extend Attrs


        /// <summary>
        /// 点赞评论信息
        /// </summary>
        /// <param name="commentReplyKey">回复关键字</param>
        /// <returns></returns>
        [HttpPost(".star/{commentReplyKey}")]
        public IResult CommentReplyStar(int commentReplyKey)
        {
            return this.ExecMethod(
                () => {
                    return this.Result(this.iComment.CommentReplyStar(
                        commentReplyKey,
                        iClientInfo.Key,
                        iClientInfo.Token));
                },
                new Tuple<bool, string>(commentReplyKey > 0, commentReplyKey > 0 ? "" : "params: commentKey is null"));
        }


        /// <summary>
        /// 取消点赞评论信息
        /// </summary>
        /// <param name="commentReplyKey">回复关键字</param>
        /// <returns></returns>
        [HttpPost(".unstar/{commentReplyKey}")]
        public IResult CommentReplyUnStar(int commentReplyKey)
        {
            return this.ExecMethod(
                () => {
                    return this.Result(this.iComment.CommentUnReplyStar(
                        commentReplyKey,
                        iClientInfo.Key,
                        iClientInfo.Token));
                },
                new Tuple<bool, string>(commentReplyKey > 0, commentReplyKey > 0 ? "" : "params: infoKey is null"));
        }


        #endregion







        #region Comment exec

        /// <summary>
        /// 添加评论回复
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public IResult Post(CommentReply model)
        {
            return this.ExecMethod(
                () => {
                    return this.Result(this.iComment.CommentReplyExec(
                        model,
                        SqlExecType.insert,
                        iClientInfo.Token));
                }, model.IsValid(IsValidEnum.reg));
        }

        /// <summary>
        /// 修改评论回复
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPut]
        public IResult Put(CommentReply model)
        {
            return this.ExecMethod(
                () => {
                    return this.Result(this.iComment.CommentReplyExec(
                        model,
                        SqlExecType.update,
                        iClientInfo.Token));
                }, model.IsValid(IsValidEnum.update));
        }

        /// <summary>
        /// 删除评论回复
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{id}")]
        public IResult Delete(int id)
        {

            return this.ExecMethod(
                () => {
                    return this.Result(this.iComment.CommentReplyExec(
                        new CommentReply
                        {
                            Id = id
                        },
                        SqlExecType.delete,
                        iClientInfo.Token));
                },
                new Tuple<bool, string>(id > 0, id > 0 ? "" : "params: id is null"));
        }





        #endregion


    }
}
